<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>

<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>

	<title>_异常单管理</title>
	<script type="text/javascript">
		
	
	   //入库订单数组
	   var exceptionIdArray=new Array();
	   var filterParam = {};
		var dataTables_sendOutFail;
		function initTable(){
			//初始化dataTables-订单回传失败
	        dataTables_sendOutFail=$("#table_sendOutFail").dataTable({
	           "bServerSide":true,
	           "sAjaxSource":'${ctx}/v2/firstPage/bindData_sendOutFail',
	           "fnServerData": retrieveData_sendOutFail,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	            "aoColumns": [ 
	                    {"mData": null,
	                    	 "mRender": function (data, display, row) {
			              		<c:forEach items="${customerList}" var="customer">
									if("${customer.customerCode}" == row.customerCode){
										return "${customer.customerName}";
									}
								</c:forEach>
								return "";
				           }
	                    },
	                    {
	                      "mData": 'order.ordeno',
	                      "render":function(obj){
	                        return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj+"' title='查看订单信息' target='_blank'>"+obj+"</a>";
	                      }
	                    },
	                    {"mData": 'customerOrderno'},
	                    {"mData": 'fromno'},
	                    {"mData": 'expressNo',
	                    "render":function(data, type, full){
	                    	return full.expressNo||full.ebillNo;
	                    }},
	                    {
	                      "mData": 'billType',
	                      "render": function (obj) {
	                         var billType=obj;
	                         if(billType=='cbill'){
	                           return "普通面单";
	                         }else if(billType=='ebill'){
	                           return "电子面单";
	                         }else{
	                           return "";
	                         }
	                      }
	                    },
	                    {"mData": 'warehouseCode'},
	                    {"mData": 'batchCode',
	                     "render":function(obj){
	                            return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+obj+"' title='查看批次信息' target='_blank'>"+obj+"</a>";
	                      }
	                    },
	                    {"mData": 'taskCode',
	                     "render":function(obj){
	                        return "<a href='${ctx}/orderMsg/v2_queryOrderMsg?_taskCode="+obj+"' title='查看任务信息' target='_blank'>"+obj+"</a>";
	                      }
	                    },
	                    {
	                      "mData": 'sendOutStatus',
	                      "render": function (obj) {
	                         var sendOutStatus=obj;
	                         if(sendOutStatus=='fail'){
	                           return "回传失败";
	                         }else{
	                         	return "";
	                         }
	                      }
	                    },
	                    {
	                      "mData": 'id',
	                      "render": function (obj) {
	                      	var id = obj;
	                      	var opeStr = "<button type=\"button\" class=\"btn btn-info\" style=\"margin-left: 10px;\" onclick=\"ajaxSendOutOrdeno('"+id+"');\" id=\"send_"+id+"\">重新回传</button>&nbsp;";
	                      	opeStr += "<a href='#djFailRemark' onclick=\"ajaxFailRemark('"+id+"');\" class='btn btn-default btn-sm' role='button' id=\"dj_"+id+"\" data-toggle='modal' >失败原因</a>";
	                      	return opeStr;
	                      }
	                    }
	             ]
	        });
	        
		}
		
		
		//回调函数_回传订单失败
		function retrieveData_sendOutFail( sSource, aoData, fnCallback ) { 
		   //查询参数
		   var customerCode=$("#_customerCode").val();
		   aoData.push( { "name": "customerCode", "value": customerCode } );  
		    
		   var warehouseCode=$("#_warehouseCode").val();
		   aoData.push( { "name": "warehouseCode", "value": warehouseCode } );
		   
		   var dataRange=$("#_dataRange").val();
		   aoData.push( { "name": "dataRange", "value": dataRange } );
		   
		   var orderno=$("#_orderno").val();
		   aoData.push( { "name": "orderno", "value": orderno } );
		    
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": function(resp) {  
		       			fnCallback(resp);
		       			$("#total_sendOutFail").html("("+resp.iTotalRecords+")");
		       		}
		   });    
		}
		
		function load(){
			var dataRange=$("#_dataRange").val();
		   if(dataRange.length==0){
		      alert("请选择日期范围...");
		      return;
		   }
		   dataTables_sendOutFail.fnDraw();
		} 
       $(function() {
	    	 //初始化日期选择框
	   		var now = new Date();
	   		var today=(now.getFullYear())+"/"+(now.getMonth()+1)+"/"+(now.getDate());    
	   		$("#_dataRange").val(today+"-"+today);
	   		$("#_dataRange").daterangepicker({format: 'YYYY/MM/DD',dateLimit :{days : 10}});
			initTable();
       });
       function  ajaxSendOutOrdeno(id){
 		  $("#send_"+id).attr("disabled",true);
 		  $.ajax({
 				type : 'post',
 				url : '${ctx}/orderMsg/ajaxSendOutOrdeno',
 				data : 'id=' + id,
 				dataType : 'json',
 				success : function(data) {
 				   jAlert(data.content);
 				},
 				error : function() {
 					jAlert("获取信息错误！");
 				}
 			});
 	  }
       var djId = null;
       var wtId = null;
       function  ajaxFailRemark(id){
    	   wtId = id;
    	   djId = '';
    	   $("#failType").val('');
    	   $("#failType").trigger("chosen:updated");
	       $("#failRemark").val('');
	       $("#finishBtn").hide()
    	   $.ajax({
				type : 'post',
				url : '${ctx}/v2/returnException/query',
				data : 'wtId=' + id,
				dataType : 'json',
				success : function(data) {
				   if(data.status == '1' ){
					   if( data.info&& data.info!='null'){
						   djId = data.info.id;
						   $("#failType").val(data.info.failType);
						   $("#failType").trigger("chosen:updated");
					       $("#failRemark").val(data.info.failRemark);
					       if(data.info.failType == 'send'){
					       	$("#finishBtn").show();
					       }
					   }
				   }else {
				       jAlert(data.content);
				   }
				},
				error : function() {
					jAlert("获取信息错误！");
				}
			});
//  		  $("#dj_"+id).attr("disabled",true);
 	  }
      function doSubmit(){
    	  $("#wtId").val(wtId);
    	  $("#djId").val(djId);
    	  if(!$("#failType").val()){
    		  jAlert("请选择标识类型");
    		  return;
    	  }
    	  if(!$("#failRemark").val()){
    		  jAlert("备注不能为空");
    		  return;
    	  }
    	 var ajaxCallUrl = '${ctx}/v2/returnException/addRemark';
    	 $.ajax({
             cache: true,
             type: "POST",
             url:ajaxCallUrl,
             data:$('#djFrom').serialize(),
             async: false,
             error: function(request) {
            	 jAlert("服务器异常!");
             },
             success: function(data) {
                 jAlert("备注成功!","温馨提示",function(){
					$("#close").trigger("click");
                	 load();
                 });
//                  $("#dj_"+dj_orderNo).attr("disabled",false);
             }
         });
      }
      
      function  doFinish(){
    	  jConfirm("确定要修正异常状态？","温馨提醒",function(result){
  			if(result){
		    	  $("#wtId").val(wtId);
		    	  $("#djId").val(djId);
		  	  	  $.ajax({
					type : 'post',
					url : '${ctx}/v2/returnException/toSendFinish',
					data : 'djId=' + djId,
					dataType : 'json',
					success : function(data) {
						jAlert(data.content,"温馨提示",function(){
							$("#close").trigger("click");
							load();
		                });
					},
					error : function() {
						jAlert("获取信息错误！");
					}
				});
  			}
    	  });
	  }
      
    </script>
</head>

<body>
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">	
	<form class="form-search" id="queryForm" method="post">
				    <!-- 第一行 -->
					<div class="form-group row">
					
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 商家： </span> 
								<select data-placeholder="请选择..." class="form-control searchSelect" id="_customerCode" onchange="ajaxAreaGroup(this,'_warehouseCode')">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.customerCode}"
											<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 仓库： </span> 
								<select class="form-control span3" id="_warehouseCode" >
									<option value=""></option>
									<c:forEach items="${warehouseList}" var="warehouse">
										<option value="${warehouse.groupCode}" >${warehouse.groupName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 订单编号： </span> 
								<input type="text" class="form-control" id="_orderno" name="_orderno">
							</div>
						</div>
						
					</div>

                    <!-- 第二行 -->
					<div class=" form-group row">

						<div class="col-sm-6">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 日期范围： </span>

								<div class="input-group">
									<div class="input-group-addon">
										<i class="fa fa-calendar"></i>
									</div>
									<input type="text" class="form-control pull-right" id="_dataRange" name="_dataRange" value="${param._fromDate}"/>
								</div>
								
							</div>
						</div>
						
						<div class="col-sm-6">
							<button class="btn btn-primary" type="button" onclick="load();">搜索</button>
						</div>
						
					</div>
					
							
	 </form>
	</div>
	</div>
	</div>
	</div>

	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">	
					<table id="table_sendOutFail" class="table table-bordered table-striped">
			         <thead>
			             <tr>
		                 	<th style="width: 50px;">商家</th>
						    <th style="width: 100px;">能容订单号</th>
						    <th style="width: 100px;">商家订单号</th>
						    <th style="width: 100px;">来源订单号</th>
						    <th style="width: 100px;">快递单号</th>
						    <th style="width: 70px;">运单类型</th>
						    <th style="width: 40px;">仓库</th>
						    <th style="width: 100px;">作业批次</th>
						    <th style="width: 100px;">作业任务</th>
						    <th style="width: 80px;">订单回传状态</th>
						    <th style="width: 160px;">操作</th>
			             </tr>
			         </thead>
			         <tfoot>
			             <tr>
			                <th style="width: 50px;">商家</th>
						    <th style="width: 100px;">能容订单号</th>
						    <th style="width: 100px;">商家订单号</th>
						    <th style="width: 100px;">来源订单号</th>
						    <th style="width: 100px;">快递单号</th>
						    <th style="width: 100px;">运单类型</th>
						    <th style="width: 50px;">仓库</th>
						    <th style="width: 100px;">作业批次</th>
						    <th style="width: 100px;">作业任务</th>
						    <th style="width: 100px;">订单回传状态</th>
						    <th style="width: 100px;">操作</th>
			             </tr>
			         </tfoot>
			     </table>
			</div>
		</div>
	</div>
	</div>
	
	<!-- 弹出窗体-订单详情 start  -->
	<div id="djFailRemark" class="modal fade">
		<div class="modal-dialog" style="width: 60%;">
			<div class="modal-content">
				<div class="modal-body">
					<form id="djFrom" action="${ctx}/v2/returnException/addRemark" >
						<input type="hidden" name="wtId" id="wtId"/>
						<input type="hidden" name="djId" id="djId"/>
						<div class="box box-solid box-primary">
				      		<div class="box-header"><span class="box-title">登记失败原因</span></div>
							<div class="box-body">
								<div class="form-group row">
									<div class="col-sm-4">
										<div class="input-textgroup col-sm-12">
											<span class="input-group-text"> 标识类型： </span> 
											<select class="form-control span3" id="failType"  name="failType" >
												<option value=""></option>
												<option value="send">客户标识已发货</option>
											</select>
										</div>
									</div>
								</div>
								<div class="form-group row">
									<div class="col-sm-9">
										<div class="input-textgroup col-sm-12">
											<span class="input-group-text"> 备注： </span> 
											<textarea class="form-control" id="failRemark" name="failRemark" style="width:500px;height:100px;"></textarea>
										</div>
									</div>
								</div>
								
								<div class="form-group row">
									<div class="col-sm-9">
										<div class="input-textgroup col-sm-12">
											
											<a href="#" onclick="doSubmit()" role="button"  class="btn btn-primary" data-toggle="modal">
												保存
											</a>
											<a href="#" id="finishBtn" onclick="doFinish()" role="button"  class="btn btn-primary" data-toggle="modal">
												修正异常状态
											</a>
											<button  id="close" class="btn" data-dismiss="modal" aria-hidden="true">
												关闭
											</button>
										</div>
									</div>
								</div>
								
							</div>
						</div>
					</form>
				</div>
				
			</div>	
		</div>
	</div>
	<!-- 弹出窗体-订单详情 end  -->
	
	</section>
</body>
</html>
